/// <reference path="../../../Resources/js/jquery/jquery.debug.js" />
/// <reference path="../../Additions/Addition.js" />
/// <reference path="../../Items/MItem.js" />
/// <reference name="MicrosoftAjax.debug.js" />

Type.registerNamespace("BM");

// TableDisplayAddition object

BM.TableDisplayAddition = function(item, additionNode) {
    BM.TableDisplayAddition.initializeBase(this, [item, additionNode]);
}

BM.TableDisplayAddition.prototype = {
	load: function() {
		BM.TableDisplayAddition.callBaseMethod(this, 'load');
		var nodeQuery = $(this.item.node);
		if (this.isItemFirst()) {
			this.onFirstSiblingShow(nodeQuery);			
		} else {
			nodeQuery.find('.Lb').hide();
		}
	},

	onFirstSiblingShow: function(nodeQuery) {
		/// <summary>
		/// Turn visibility for labels and add CSS class for title contained in nodeQuery object 
		/// </summary>
		/// <param name="nodeQuery" type="Object" mayBeNull="false">
		/// Object
		/// </param>
		/// <returns />
		nodeQuery.find('.Lb').show();
		nodeQuery.find('.Title').addClass("FstTitle");
	},

	unload: function() {
		BM.TableDisplayAddition.callBaseMethod(this, 'unload');
		var itemIndex = parseInt(this.item.getIndex());
		var siblings = this.item.getSiblings();
		if (siblings[0] == this.item && siblings.length > 1) {			
			this.onFirstSiblingShow($(siblings[1].node));			
		}
	},

	isItemFirst: function() {
		var siblings = this.item.getSiblings();
		return siblings[0] == this.item;
	}
}

BM.TableDisplayAddition.registerClass("BM.TableDisplayAddition", BM.Addition);
